package com.ruoyi.web.config;

import com.gitee.deeround.jdbchelper.DbAction;
import com.gitee.deeround.jdbchelper.resultSetExtractors.CustomApply;
import com.ruoyi.core.entity.BaseMap;
import com.ruoyi.flow.listener.FlowListenerContainer;
import com.ruoyi.web.listener.DefaultFlowListener;
import com.ruoyi.web.listener.custom.QjFlowListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

@Configuration
public class FlowConfig {

    @Autowired
    private DbAction dbAction;

    @PostConstruct
    private void init() {

        List<BaseMap> list = dbAction.queryForListObject("select * from sys_mod where status='1' and is_flow='1'", new CustomApply<BaseMap>() {
            @Override
            public BaseMap apply(Map<String, Object> map) {
                return new BaseMap(map);
            }
        });

        for (BaseMap baseMap : list) {
            if (!baseMap.isEmpty("machine_id")) {
                if ("17183297285521408".equals(baseMap.getString("machine_id"))) { // 特殊监听，注入自己写的监听实现类
                    FlowListenerContainer.register("17183297285521408", new QjFlowListener());
                } else { // 否则使用默认监听即可
                    FlowListenerContainer.register(baseMap.getString("machine_id"), new DefaultFlowListener());
                }
            }
        }


    }

}
